package com.mindbook.vip.gawxchatinfo.controller.file;

import com.mindbook.vip.gawxchatinfo.utils.file.FileUploadUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @NAME: wxb
 * @DATE: 2022/6/20
 * @DESCRIPTION: 文件上传的操作
 **/
@Api(tags = "文件上传")
@RestController
@RequestMapping("file")
public class UploadController {

    @Autowired private FileUploadUtils fileUploadUtils;

    /**
     * 将文件保存
     * @param file
     * @param request
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "文件上传")
    @PostMapping("/")
    public Result fileUpload(MultipartFile file, HttpServletRequest request) throws IOException {
        String fileSrc = fileUploadUtils.fileUpload(file, request);
        return ResultUtils.genSuccessResult(fileSrc);
    }

}
